package _mst;

import _object.TreeNode;

/**
 * 面试题 04.10. 检查子树
 */
public class T0410 {
    public boolean checkSubTree(TreeNode t1, TreeNode t2) {
        if (t1 == null) return null == t2;
        return isSame(t1, t2) || checkSubTree(t1.left, t2) || checkSubTree(t1.right, t2);
    }

    private boolean isSame(TreeNode node1, TreeNode node2) {
        if (node1 == null || node2 == null) return node1 == node2;
        return node1.val == node2.val && isSame(node1.left, node2.left) && isSame(node1.right, node2.right);
    }
}
